﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

public partial class Default : System.Web.UI.Page
{

    public string neareastVideo = "";     //推荐视频
    public string tjkc = "";           //推荐视频列表
    public string helpcenter = "";      //帮助中心
    public string Details = "";
    public string advertise = "";    //广告图片或flash
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["username"] != null && Session["userpwd"] != null)
            {
                Hidden1.Value = Session["username"].ToString();
            }
            neareastVideo = NeareastVideo().ToString();
            tjkc = Tjsp().ToString();
            Details = spDetails().ToString();
            //helpcenter = HelpCenter().ToString();
            AdvertiseDAL dal = new AdvertiseDAL();
            if (dal.Get("Advertise") != null)
            {
                if (!string.IsNullOrEmpty(dal.Get("Advertise").Content))
                    advertise = dal.Get("Advertise").Content;
                else
                    advertise = "<img src=\"images/客服广告.jpg\" width=\"710\" height=\"180\" />";
            }
            else
            {
                advertise = "<img src=\"images/客服广告.jpg\" width=\"710\" height=\"180\" />";
            }
        }
    }
    private Web_VedioBLL videoBll;
    /// <summary>
    /// 视频业务类
    /// </summary>
    private Web_VedioBLL VideoBll
    {
        get
        {
            if (videoBll == null)
            {
                videoBll = new Web_VedioBLL();
            }
            return videoBll;
        }
    }
    //public StringBuilder HelpCenter()
    //{
    //}
    /// <summary>
    /// 最近的视频对象
    /// </summary>
    /// <returns></returns>
    protected StringBuilder NeareastVideo()
    {
        StringBuilder sbVideo = new StringBuilder();
        //Web_video video = VideoBll.GetNeareastVideo();

        Web_video_imgDAL webimg = new Web_video_imgDAL();
        DataTable dt = VideoBll.Zxjc;
        if (dt != null)
        {
            System.Data.DataRow sRow = dt.Rows[0];
            string sId = Convert.ToString(sRow["v_id"]);
            string sTitle = Convert.ToString(sRow["v_title"]);
            string url = Convert.ToString(sRow["V_url"]);
            int classid = Convert.ToInt32(sRow["classid"]);
            string setup_user = Convert.ToString(sRow["setup_user"]);
            DateTime setup_date = DateTime.Parse(sRow["setup_date"].ToString());
            int star = int.Parse(sRow["v_star"].ToString());
            string remark = Convert.ToString(sRow["v_remark"]);
            url = url.Substring(0, url.IndexOf("$"));
            Web_video_img img = webimg.GetElementById(sId, classid);
            sbVideo.AppendLine("<div class=\"videoR_c_l\" id=\"player\">");
            if (img != null)
                sbVideo.AppendLine("<img src=\"uploadimages/" + img.V_img + "\" alt=\"" + sTitle + "\" width=\"132\" height=\"106\" style=\"float: left\"/>");
            else
                sbVideo.AppendLine("<img src=\"uploadimages/pig1.jpg\" alt=\"" + sTitle + "\" width=\"132\" height=\"106\" style=\"float: left\"/>");

            sbVideo.AppendLine("<div class=\"videoR_c_l1\" > <ul><li><span class=\"font14 font-weight gray_t\"  id=\"video_serise\"><a href=\"" + url + "\" target=\"_blank\">" + sTitle + "</a></span></li>");
            sbVideo.AppendLine("<li><span class=\"font14\" id=\"teacher\">讲师：" + setup_user + "</span></li>");
            sbVideo.AppendLine("<li><span class=\"font14\" id=\"ctime\">时间：" + setup_date.ToShortDateString() + "</span></li >");
            sbVideo.AppendLine("<li id=\"stars\"><span class=\"font14\" >推荐：</span>");
            for (int j = 0; j < star; j++)
            {
                sbVideo.AppendLine("<img src=\"images/ico_star.jpg\" />");
            }
            sbVideo.AppendLine("</li></ul></div>");
            sbVideo.AppendLine("<div class=\"videoR_c_l2 font14 marginTop10\" id=\"remark\">" + remark + "<span class=\"b font14\">&nbsp;&nbsp;<a href=\"" + url + "\" id=\"details\" target=\"_blank\" class=\"b font14\">[详细]</a></span></div></div>");

        }
        else
        {
            sbVideo.AppendLine("<div>服务器忙，请重试</div>");
        }
        return sbVideo;
    }
    /// <summary>
    /// 推荐视频
    /// </summary>
    /// <returns></returns>
    protected StringBuilder Tjsp()
    {
        StringBuilder sbTjsp = new StringBuilder();
        DataTable dt = VideoBll.Zxjc;
        if (dt != null)
        {
            Web_video_imgDAL webimg = new Web_video_imgDAL();

            sbTjsp.AppendLine("<div class=\"videoR_c_r\" att=\"video\"><ul>");
            for (int i = 0; i < 4; i++)
            {
                System.Data.DataRow sRow = dt.Rows[i];
                int sId = Convert.ToInt32(sRow["v_id"]);
                string sTitle = Convert.ToString(sRow["v_title"]);
                string url = Convert.ToString(sRow["V_url"]);
                int classid = Convert.ToInt32(sRow["classid"]);
                url = url.Substring(0, url.IndexOf("$"));
                //Web_video_img img = webimg.GetElementById(sId, classid);
                //sbTjsp.Append("<li><a href=\"#\" url=\"" + url + "\">" + sTitle + "</a></li>\r\n");
                //需修改一下图片路径，添加同步图片
                //if (img != null)
                sbTjsp.Append("<li><img src=\"uploadimages/service" + i + ".jpg" + "\" width=\"172\" height=\"55\" style=\"display:block;cursor:pointer;\" alt=\"" + sTitle + "\" onclick=\"change(" + i + ")\"/>");
                //else
                //sbTjsp.Append("<li><img src=\"images/1px.bmp\" width=\"172\" height=\"55\" style=\"display:block;cursor:pointer;\" alt=\"" + sTitle + "\" onclick=\"change(" + i + ")\"/>");
                sbTjsp.Append("</li>");
                //if (i == 4)
                //    break;
            }
            sbTjsp.AppendLine("</ul></div>");
        }
        else
        {
            sbTjsp.AppendLine("<div>服务器忙，请重试</div>");
        }
        return sbTjsp;
    }
    protected StringBuilder spDetails()
    {
        StringBuilder sbTjsp = new StringBuilder();
        DataTable dt = VideoBll.Zxjc;
        if (dt != null)
        {
            Web_video_imgDAL webimg = new Web_video_imgDAL();

            for (int i = 0; i < 4; i++)
            {
                System.Data.DataRow sRow = dt.Rows[i];
                string sId = Convert.ToString(sRow["v_id"]);
                string sTitle = Convert.ToString(sRow["v_title"]);
                string url = Convert.ToString(sRow["V_url"]);
                int classid = Convert.ToInt32(sRow["classid"]);
                string setup_user = Convert.ToString(sRow["setup_user"]);
                DateTime setup_date = DateTime.Parse(sRow["setup_date"].ToString());
                int star = int.Parse(sRow["v_star"].ToString());
                string remark = Convert.ToString(sRow["v_remark"]);
                url = url.Substring(0, url.IndexOf("$"));
                Web_video_img img = webimg.GetElementById(sId, classid);
                sbTjsp.AppendLine("<div class=\"videoR_c_l\" id=\"player" + i + "\" style=\"display:none\">");
                if (img != null)
                    sbTjsp.AppendLine("<img src=\"uploadimages/" + img.V_img + "\" alt=\"" + sTitle + "\" width=\"132\" height=\"106\" style=\"float: left\"/>");
                else
                    sbTjsp.AppendLine("<img src=\"uploadimages/pig1.jpg\" alt=\"" + sTitle + "\" width=\"132\" height=\"106\" style=\"float: left\"/>");

                sbTjsp.AppendLine("<div class=\"videoR_c_l1\" > <ul><li><span class=\"font14 font-weight gray_t\"  id=\"video_serise\"><a href=\"" + url + "\" target=\"_blank\">" + sTitle + "</a></span></li>");
                sbTjsp.AppendLine("<li><span class=\"font14\" id=\"teacher\">讲师：" + setup_user + "</span></li>");
                sbTjsp.AppendLine("<li><span class=\"font14\" id=\"ctime\">时间：" + setup_date.ToShortDateString() + "</span></li >");
                sbTjsp.AppendLine("<li id=\"stars\"><span class=\"font14\" >推荐：</span>");
                for (int j = 0; j < star; j++)
                {
                    sbTjsp.AppendLine("<img src=\"images/ico_star.jpg\" />");
                }
                sbTjsp.AppendLine("</li></ul></div>");
                sbTjsp.AppendLine("<div class=\"videoR_c_l2 font14 marginTop10\" id=\"remark\">" + remark + "<span class=\"b font14\">&nbsp;&nbsp;<a href=\"" + url + "\" id=\"details\" target=\"_blank\" class=\"b font14\">[详细]</a></span></div></div>");
                //if (i == 4)
                //    break;
            }
        }
        else
        {
            sbTjsp.AppendLine("<div>服务器忙，请重试</div>");
        }
        return sbTjsp;
    }
}